package com.yl.zqy.vo.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

@Getter
@Setter
@Schema(name = "自定义精简分页对象", description = "自定义精简分页对象")
public class IPageVo<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "记录")
    List<T> records;
    @Schema(description = "总数")
    Long total;
    @Schema(description = "页大小")
    Long size;
    @Schema(description = "当前页")
    Long current;
    @Schema(description = "总页数")
    Long pages;

    public static <T> IPageVo<T> of(long current, long size) {
        return of(current, size, 0);
    }

    public static <T> IPageVo<T> of(long current, long size, long total) {
        return new IPageVo<>(current, size, total);
    }

    public static <T> IPageVo<T> of(IPage<T> page) {
        IPageVo<T> vo = new IPageVo<>();
        vo.setCurrent(page.getCurrent());
        vo.setSize(page.getSize());
        vo.setTotal(page.getTotal());
        vo.setPages(page.getPages());
        vo.setRecords(page.getRecords());
        return vo;
    }

    public IPageVo() {
        this(1, 20);
    }

    public IPageVo(long current, long size) {
        this(current, size, 0);
    }

    public IPageVo(long current, long size, long total) {
        this.current = current;
        this.size = size;
        this.total = total;
    }
}
